
//订阅者类
class Watcher{
    /**
     * 
     * @param {订阅的元素节点} node 
     * @param {全局数据对象} vm 
     * @param {回调} callback 
     */
    constructor(vm, expr, callback){
        this.vm = vm;
        this.expr = expr;
        this.callback = callback;
        this.value = this.get();
    }

    get(){
        Dep.target = this;

        let value = this.vm.$data[this.expr];

        Dep.target = null;
        return value;
    }

    //更新方法(发布后要做的事)
    update(){

        var newValue = this.vm.$data[this.expr];
        var oldValue = this.value;

        if(newValue !== oldValue){
            this.callback(newValue);
        }
    }
}